/**
 * Copyright (c) 2024 - CARThunder
 * All Rights Reserved by Chengdu CARThunder Intelligent Technology Co., LTD and its affiliates.
 * You may not use, copy, distribute, modify, transmit in any form this file
 * except in compliance with CARThunder in writing by applicable law.
 *
 */

/**
 * file description.
 * @file    filename
 * @brief   brief function description.
 * @details detailed function description.
 * @version 1.0
 * @author  author_name
 * @date    last_modified_date
 *
 *      Edit History
 *      ----------------------------------------------------------------------------
 *      DATE                     NAME               DESCRIPTION
 *      2024-08-06            jia fengyi        Create it.
 *
 */

package com.cart.musicdemo.base.utils;

public class StringUtils {

    private static final int TITLE_MAX_LENGTH = 40;
    private static final int SUB_START_INDEX = 0;
    private static final int ELLIPSIS_BITS = 3;

    public static String subString(String title,String artist) {
        // 拼接两个字符串
        StringBuilder sb = new StringBuilder(title)
                .append("  -  " + artist);
        String name;
        // 检查拼接后的字符串长度是否超过最大长度
        if (sb.length() > TITLE_MAX_LENGTH) {
            // 如果超过，截取前maxLength-3个字符，并添加省略号
            name = sb.substring(SUB_START_INDEX, TITLE_MAX_LENGTH - ELLIPSIS_BITS) + "...";
        } else {
            // 如果没有超过，返回原始拼接字符串
            name =  sb.toString();
        }
        return name;
    }
}
